<template>
  <div>
    <div class="my-heard">
      <h1>
        <img src="img/Tripadvisor_header.svg" alt="" />
      </h1>
      <div class="heard-right">
        <div style="border: none" class="heard-block">
          <i class="el-icon-edit"></i>
          <span>点评</span>
        </div>
        <div style="border: none" class="heard-block" @click="goCollection()">
          <i class="el-icon-star-off"></i>
          <span>旅行</span>
        </div>
        <!-- 如果用户存在 显示默认照片 -->
        <div
          v-if="$store.state.islogin"
          style="width: 40px; height: 40px; padding: 0"
          class="heard-block"
        >
          <!-- @click="showAdd" -->
          <img
            class="btn"
            style="width: 40px; height: 40px; border: none; border-radius: 50%"
            src="/detail_f2_img/img_scenic/head.png"
            alt=""
            @click="showArea = !showArea"
          />
          <div class="menu" v-show="showArea">
            <div @click="goPerson()">个人页面</div>
            <div>账号信息</div>
            <div @click="logout">退出</div>
          </div>
        </div>
        <!-- 判断用户名是否存在 不存在 就显示登录按钮 -->
        <div
          v-else
          style="background-color: black; color: white; border: none"
          class="heard-block"
        >
          <i class="el-icon-s-custom"></i>
          <span @click="go()"> 登录 </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations, mapState } from "vuex";
export default {
  components: {
    //利用辅助函数 引入vuex中的uphone
    ...mapState(["uphone"]),
  },
  data() {
    return {
      showArea: false,
    };
  },
  methods: {
    ...mapMutations(["loginok"], ["logout"]),
    go() {
      this.$router.push("/login");
    },
    goPerson() {
      this.$router.push("/person");
    },
    goCollection() {
      this.$router.push("/collection");
    },
    // showAdd: function () {
    //   if (this.showArea) {
    //     this.showArea = false;
    //   } else {
    //     this.showArea = true;
    //   }
    // },
    logout() {
      window.sessionStorage.clear(); //销毁token
      this.$router.push("/login");
    },
  },
};
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}

.my-heard {
  width: 1280px;
  margin: 0 auto;
  height: 60px;
  display: flex;
  justify-content: space-between;
  img {
    width: 225px;
    height: 66px;
  }
}

.heard-right {
  color: black;
  display: flex;
  cursor: pointer;
  .heard-block {
    display: flex;
    flex-direction: row;
    font-size: 16px;
    font-weight: 700;
    vertical-align: middle;
    padding: 10px 16px;
    margin-left: 8px;
    width: 60px;
    height: 20px;
    border: 1px solid #bbb;
    border-radius: 20px;
    margin-top: 10px;
    position: relative;

    > span {
      margin-left: 5px;
    }
    > i {
      margin-top: 3px;
    }
  }
}
.menu {
  //display: none;
  z-index: 100;
  position: absolute;
  width: 164px;
  height: 120px;
  background-color: #fff;
  border-radius: 20px;
  top: 50px;
  right: 0px;
  padding: 8px 16px;
  box-sizing: border-box;
  box-shadow: 0 2px 54px rgba(0, 0, 0, 0.1);
  > div {
    padding: 7px;
    font-size: 16px;
    font-weight: normal;
    &:hover {
      background-color: #e1e1e1e1;
    }
  }
}
</style>
